//
//  NSObject+Extend.h
//  RMMaterialRed
//
//  Created by XBWH on 2024/3/13.
//

#import <Foundation/Foundation.h>

///从字典中取出数组
#define RBSafeArray(dictionary,key)   [dictionary rb_safeArrayForKey:key]
///从字典中取出字典
#define RBSafeDic(dictionary,key)   [dictionary rb_safeDictionaryForKey:key]
///从字典中取出字符串
#define RBSafeString(dictionary,key)   [dictionary rb_safeStringForKey:key]
///从字典中取出int值
#define RBSafeInt(dictionary,key)   [dictionary rb_safeIntegerForKey:key]

///根据索引从数组取值
#define RBSafeArrayIndex(array,index)   [array rb_safeArrayWithIndex:index]
#define RBSafeDicIndex(array,index)   [array rb_safeDictionaryWithIndex:index]

NS_ASSUME_NONNULL_BEGIN

@interface NSObject (Extend)
#pragma mark -本类为字典类型
/**
 取出字典
 @param key @"data" 或者 @"data|data|result"
 @return 返回字典对象
 */
- (NSDictionary*)rb_safeDictionaryForKey:(NSString*)key;

/**
 取出数组
 @param key @"data" 或者 @"data|data|result"
 @return 返回数组对象
 */
- (NSArray*)rb_safeArrayForKey:(NSString*)key;

/**
 取出字符串
 @param key @"data" 或者 @"data|data|result"
 @return 返回字符串对象
 */
- (NSString*)rb_safeStringForKey:(NSString*)key;

/**
 取出int值
 @param key @"data" 或者 @"data|data|result"
 @return 返回int值
 */
- (NSInteger)rb_safeIntegerForKey:(NSString*)key;

#pragma mark -本类为数组类型
//根据索引取出数组
- (NSArray*)rb_safeArrayWithIndex:(NSInteger)index;
//根据索引取出字典
- (NSDictionary*)rb_safeDictionaryWithIndex:(NSInteger)index;

@end

NS_ASSUME_NONNULL_END
